﻿@{
    Layout = null;
}

@using MVC_Project.Model;
@model MVC_Project.Model.Users

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title></title>
    @Styles.Render("~/layui/css")
</head>
<body>
    <div>
        @using (Ajax.BeginForm("Create", "Users", new AjaxOptions()
        {
            HttpMethod = "POST",
            OnSuccess = "mySuccess"
        }, new
        {
            style = "width: 450px;margin: 20px;",
            @class = "layui-form layui-form-pane",
            //lay -filter = "myform"
        }))
        {
            <!-- 姓名 -->
            <div class="layui-form-item">
                <label class="layui-form-label">姓名</label>
                <div class="layui-input-block">
                    <input type="text" name="name" value="Test" lay-verify="required|username" placeholder="请输入账户" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <!-- 性别 -->
            <div class="layui-form-item" pane>
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="男" title="男">
                    <input type="radio" name="sex" value="女" title="女" checked>
                </div>
            </div>

            <!-- 账户 -->
            <div class="layui-form-item">
                <label class="layui-form-label">账户</label>
                <div class="layui-input-block">
                    <input type="text" name="loginName" value="test123" lay-verify="required" placeholder="请输入账户" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <!-- 密码 -->
            <div class="layui-form-item">
                <label class="layui-form-label">密码</label>
                <div class="layui-input-inline">
                    <input type="password" name="loginPwd" value="123" lay-verify="required" placeholder="请输入密码" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <!-- 手机 -->
            <div class="layui-form-item">
                <label class="layui-form-label">手机</label>
                <div class="layui-input-block">
                    <input type="text" name="phone" value="18855556666" lay-verify="required" placeholder="请输入手机号码" autocomplete="off"
                           class="layui-input">
                </div>
            </div>

            <!-- 部门 -->
            <div class="layui-form-item">
                <label class="layui-form-label">部门</label>
                <div class="layui-input-block selectUp">
                    <select>
                        @{
                            foreach (var d in ViewBag.depts as List<Department>)
                            {
                                <option value="@d.deptID">@d.deptName</option>
                            }
                        }
                    </select>

                </div>
            </div>
            <!-- 角色 -->
            <div class="layui-form-item">
                <label class="layui-form-label">角色</label>
                <div class="layui-input-block selectUp">
                    <select name="roleID">
                        @{
                            foreach (var r in ViewBag.roles as List<MVC_Project.Model.Roles>)
                            {
                                <option value="@r.roleID">@r.roleName</option>
                            }
                        }
                    </select>

                </div>
            </div>


            <!-- 状态 -->
            <div class="layui-form-item" pane>
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="status" checked="checked" value="true"  lay-skin="switch" lay-text="正常|冻结">
                </div>
            </div>

            <!-- 按钮 -->
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <input type="submit" lay-submit class="layui-btn" value="立即提交">
                    <input type="reset" class="layui-btn layui-btn-primary" value="取消">
                </div>
            </div>

        }
    </div>

    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/layui")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/jqueryajax")

    <script type="text/javascript">

        var layer;
        layui.use(["form", "layer"], function () {
            var form = layui.form, layer = layui.layer;
            form.render();
          
        })

        function mySuccess(data) {
            console.log(data);
            if (data.code == 1) {
                parent.layer.closeAll();
                parent.layer.msg(data.msg, { icon: 1 });

                //获取父窗口中正打开（show）的子窗口（iframe）
                let iframeWindow = $(parent.document).find(".layui-show iframe")[0].contentWindow;
                //调用父窗口中当前显示窗口属性表格数据
                iframeWindow.tableIns.reload({
                    where: { //设定异步数据接口的额外参数，任意设
                        name: $("#edtSearch").val()
                    }
                    , page: {
                        curr: 1 //重新从第 1 页开始
                    }
                });
            } else {
                layer.msg(data.msg, { icon: 2 });
            }
        }
    </script>
</body>
</html>
